//
//  GTWeChatDynamicTool.m
//  GTW
//
//  Created by Ran on 15/11/13.
//  Copyright (c) 2015年 xcode. All rights reserved.
//

#import "GTWeChatDynamicTool.h"

@implementation GTWeChatDynamicTool

static NSString *const stringDemo = @"淡fg";

+ (CGSize)getTextSizeWithText:(NSString *)text width:(CGFloat)width attribute:(NSDictionary *)attribute
{
    return [text boundingRectWithSize:CGSizeMake(width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:attribute context:nil].size;
}

+ (CGSize)getTextSizeWithText:(NSString *)text attribute:(NSDictionary *)attribute
{
    return [self getTextSizeWithText:text width:MAXFLOAT attribute:attribute];
}

+ (CGFloat)getTextHeightWithAttribute:(NSDictionary *)attribute
{
    return [self getTextSizeWithText:stringDemo attribute:attribute].height;
}

+ (void)setLabel:(UILabel *)label withAttribute:(NSDictionary *)attribute
{
    label.textColor = attribute[NSForegroundColorAttributeName];
    label.font = attribute[NSFontAttributeName];
}

+ (void)setButton:(UIButton *)button withAttribute:(NSDictionary *)attribute
{
    [button setTitleColor:attribute[NSForegroundColorAttributeName] forState:UIControlStateNormal];
    button.titleLabel.font = attribute[NSFontAttributeName];
}

+ (UILabel *)labelWithAttribute:(NSDictionary *)attribute
{
    UILabel *label = [[UILabel alloc] init];
    [self setLabel:label withAttribute:attribute];
    return label;
}

+ (UIButton *)buttonWithAttribute:(NSDictionary *)attribute
{
    UIButton *button = [[UIButton alloc] init];
    [self setButton:button withAttribute:attribute];
    return button;
}

+ (GTWeChatDynamicLinkButton *)linkButtonWithAttribute:(NSDictionary *)attribute
{
    GTWeChatDynamicLinkButton *button = [GTWeChatDynamicLinkButton buttonWithType:UIButtonTypeCustom];
    [self setButton:button withAttribute:attribute];
    return button;
}

@end
